<!--
 * @Author: WuFeng <763467339@qq.com>
 * @Date: 2022-04-12 18:47:17
 * @LastEditTime: 2022-07-29 17:10:47
 * @LastEditors: WuFeng <763467339@qq.com>
 * @Description: 新建 / 编辑 页面
 * @FilePath: \vue3-element-plus-web\src\views\SysManage\Monitor\components\Drawer\settings.vue
 * Copyright 版权声明
-->
<template>
  <div class="">
    <el-form
      :rules="rules"
      ref="dataForm"
      :model="temp"
      label-width="130px"
      style='width:100%;'
    >

      <el-form-item label="开启监控：" prop="status">
        <el-switch v-model="temp.status" :active-value="1" :inactive-value="0" />
      </el-form-item>

      <el-form-item label="是否入库：" prop="isSave">
        <el-switch v-model="temp.isSave" :active-value="1" :inactive-value="0" />
      </el-form-item>

      <el-form-item label="监控间隔(秒)：" prop="internal">
        <el-input-number
          v-model="temp.internal"
          :min="5"
          :max="300"
          controls-position="right"
          placeholder="监控间隔(秒)"
          style="width: 180px;"
        />
      </el-form-item>

    </el-form>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { monitorGetSettings } from '@/api/SysManage/monitor'

export default {
  name: 'Create',
  computed: {
    ...mapGetters([
      'drawerCurrent'
    ]),
    drawerType: function() {
      return this.drawerCurrent.drawerType
    }
  },
  components: {
  },
  data() {
    return {
      pageParams: {},
      temp: {
        status: 1,
        isSave: 1,
        internal: 5
      },
      rules: {
        internal: [
          { required: true, message: '请输入监控间隔', trigger: 'change' }
        ]
      }
    }
  },
  watch: {
    // 表单内容体
    temp: {
      handler: function(val, oldVal) {
      },
      deep: true
    }
  },
  async created() {
    // ******************* 需要从接口数据的话执行一下操作
    // drawer loadding 状态 打开
    this.$store.dispatch('SetDrawerloading', true)
    const res = await monitorGetSettings()
    this.temp = Object.assign({}, this.temp, res.data)
    // drawer loadding 状态 关闭
    this.$store.dispatch('SetDrawerloading', false)
  },
  mounted() {

  },
  methods: {
    // 提交表单
    submitForm() {
      return this.$refs['dataForm'].validate()
    },
    // 获取表单数据
    getFormData() {
      const res = {
        internal: this.temp.internal
      }
      if (this.temp.status === 1) {
        res.status = 1
      }
      if (this.temp.isSave === 1) {
        res.isSave = 1
      }
      return res
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
